package services

import (
	"dog-blog/base/storage"
	"dog-blog/base/utils/exec"

	"github.com/mojocn/base64Captcha"
)

type configJsonBody struct {
	Id            string
	CaptchaType   string
	VerifyValue   string
	DriverAudio   *base64Captcha.DriverAudio
	DriverString  *base64Captcha.DriverString
	DriverChinese *base64Captcha.DriverChinese
	DriverMath    *base64Captcha.DriverMath
	DriverDigit   *base64Captcha.DriverDigit
}

var store = base64Captcha.DefaultMemStore

// 获取验证码
func CaptchaGenerate() (id, b64s string, err error) {
	e := configJsonBody{}
	e.DriverDigit = base64Captcha.NewDriverDigit(40, 120, 4, 0.7, 80)
	driver := e.DriverDigit
	cap := base64Captcha.NewCaptcha(driver, store)
	return cap.Generate()
}

// 校验验证码
func CaptchaVerify(id, code string, clear bool) bool {
	return store.Verify(id, code, clear)
}

func GitArticle(option string) (string, error) {
	path := storage.GetBasic().Posts
	return exec.RunGitCommand(path, "git", option)
}
